package com.example.cosid;

import me.ahoo.cosid.snowflake.AbstractSnowflakeId;

/**
 * long类型位数过长, 前端数值类型溢出.<hr/>
 * 不能直接返回数字类型, 需返回字符串. 如: <br/>"7168946595545747457"
 */
public class CosSnowflakeId extends AbstractSnowflakeId implements SnowflakeIdGenerator {
    /**
     * 起始时间 2024-01-01 00:00:00 (秒)
     */
    private static final long EPOCH = 1704038400L;
    /** 时间-位数 */
    private static final int TIMESTAMP_BIT = 41;
    /** 机器号-位数 */
    private static final int MACHINE_BIT = 10;
    /** 自增序号-位数 */
    private static final int SEQUENCE_BIT = 12;

    /**
     * @param machineId 机器ID
     * @param sequenceResetThreshold 序号重置点
     */
    public CosSnowflakeId(int machineId, long sequenceResetThreshold) {
        super(EPOCH, TIMESTAMP_BIT, MACHINE_BIT, SEQUENCE_BIT, machineId, sequenceResetThreshold);
    }

    @Override
    protected long getCurrentTime() {
        return System.currentTimeMillis();
    }
}
